AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
util.PrecacheSound( "common/warning.wav" )

include('shared.lua')

local Ground = 1 + 0 + 2 + 8 + 32

function ENT:Initialize()
	self.Entity:SetModel( "models/props_c17/lampshade001a.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetMaterial("models/props_combine/combinethumper002");
	
	local phys = self.Entity:GetPhysicsObject()
	self.NextThink = CurTime() + 3
	if (phys:IsValid()) then
		phys:Wake()
		phys:SetMass(50)
	end
	self.val1 = 0
	self.val2 = 0
	self.soundon = 0
	LS_RegisterEnt(self.Entity)
	RD_AddResource(self.Entity, "rawwater", 0)
	RD_AddResource(self.Entity, "suction", 2)	
end

function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end

	local SpawnPos = tr.HitPos + tr.HitNormal * 75

	local ent = ents.Create( "nozzle_small" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:OnRemove()
	Dev_Unlink_All(self.Entity)
end

function ENT:Think()
	self.val1 = RD_GetResourceAmount(self.Entity, "suction")

	if ( self.Active == false ) then
		self:SetOverlayText( "Small Pump Nozzle\n(OFF)"  )
	else
		self:SetOverlayText( "Small Pump Nozzle\n(ON)"  )
	end

	if (self.val1 > 0) && (self.environment.inwater == 1) && (self.environment.habitat == 1) then
		RD_SupplyResource(self.Entity, "rawwater", 1)
		RD_ConsumeResource(self, "suction", 2)
		if ( self.soundon == 0 ) then
			self.soundon = 1
		end
		self.Active = true
	else
		self.soundon = 0
		self.Active = false
	end

	if (self.environment.inwater == 0) then
		self.Entity:EmitSound( "common/warning.wav" )
	end
end

function ENT:PreEntityCopy()
	RD_BuildDupeInfo(self.Entity)
end

function ENT:PostEntityPaste( Player, Ent, CreatedEntities )
	RD_ApplyDupeInfo(Ent, CreatedEntities)
end
